import java.util.PriorityQueue;
import java.util.Scanner;

public class Test2 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while (in.hasNextInt()) {
            int n = in.nextInt();
            int[] hash = new int[10001];
            int max = 0;
            for (int i = 0; i < n; i++) {
                int num = in.nextInt();
                hash[num]++;
                max = Math.max(max, num);
            }

            int[] dp = new int[max + 1];
            dp[0] = 0;
            dp[1] = hash[1] * 1;
            for (int i = 2; i <= max; i++) {
                dp[i] = Math.max(dp[i - 1], dp[i - 2] + hash[i] * i);
            }
            System.out.println(dp[max]);
        }
    }
}
